/*
 *  Copyright (C) 2011 felixtheripper <felixtheripper_AT_gmail.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
/**
 *
 * @author felixtheripper
 *
 * email: felixtheripper_AT_gmail.com
 * ... please remove "_AT_" from the above string to get the right email address
 *
 */


package org.myorg.ctm.etk.gui.swg.display.dialog;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;

import org.myorg.shr.gui.swg.display.button.BtnAbs;
import org.myorg.ctm.etk.gui.swg.display.border.EtkBorder;
import org.myorg.ctm.etk.gui.swg.display.button.BtnIcnCloseWindow;


/**
 *
 * 
 */

abstract public class DlgEViewSrcFileTxtAbs extends DlgEscapeAbs implements
    ActionListener
{
    // ---------------------------
    // FINAL STATIC PRIVATE STRING

    /**
     *
     */

    final static private long serialVersionUID = 1L;
    final static private String _f_s_strFilePathNo = "file path: dummy";
    final static private String _f_s_strFileSourceNo = "file source: dummy";


    // ------
    // PUBLIC

    @Override
    public void destroy()
    {
        if (this._btnClose != null)
        {
            this._btnClose.destroy();
            this._btnClose = null;
        }

        super.destroy();
    }


    public void actionPerformed(ActionEvent evtAction)
    {
        //String strMethod = "actionPerformed(evtAction)";

        if (! (evtAction.getSource() instanceof BtnIcnCloseWindow))
        {
        	//TODO: show error then exit
            //MySystem.s_printOutExit(this, strMethod, "wrong source instance");
        }

        _cancel();
    }



    public void windowClosing(WindowEvent e)
    {
        _cancel();
    }

    public boolean init()
    {
        JPanel pnlDisplaySource = _createPanelFilePath();

        // --------------


        this._tpeFileSource = new JTextPane();
        this._tpeFileSource.setEditable(false);

        JPanel pnl = new JPanel();
        pnl.setLayout(new BorderLayout() );
        pnl.add(this._tpeFileSource, BorderLayout.CENTER);

	    JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroller.getViewport().add(pnl);

        // --------------

        JPanel pnlOkButton = _createPanelOkButton();

        // -------
        Container cntContentPane = getContentPane();
        cntContentPane.setLayout(new BorderLayout());

        JPanel pnlAll = new JPanel();
        // --- BEGIN border

	    EtkBorder.s_setEtched(pnlAll);

	    // --- END border
	    cntContentPane.add(pnlAll, BorderLayout.CENTER);

	    pnlAll.setLayout(new BoxLayout(pnlAll, BoxLayout.Y_AXIS));
	    pnlAll.add(pnlDisplaySource);
	    pnlAll.add(Box.createVerticalStrut(10));
	    pnlAll.add(scroller);
	    pnlAll.add(Box.createVerticalStrut(10));
	    pnlAll.add(pnlOkButton);



        // ending
        return true;
    }


    // ---------
    // PROTECTED

    protected DlgEViewSrcFileTxtAbs(Component cmpFrameOwner, String strTitleApplication)
    {
        super((Frame) cmpFrameOwner, true); // true ==> modal=true

        this._btnClose = new BtnIcnCloseWindow((ActionListener) this);

        String strTitleThis = "view source file";

        setTitle(strTitleApplication + " - " + strTitleThis);
    }


    protected boolean _show_(String strSource, String strName)
    {
        //String strMethod = "_show_(strSource, strName)";

        if (strSource==null || strName==null)
        {
            //MySystem.s_printOutError(this, strMethod, "nil arg");
            return false;
        }

        if (this._tpeFileSource == null)
        {
            //MySystem.s_printOutError(this, strMethod, "nil this._tpeFileSource");
            return false;
        }

        this._tpeFileSource.setText(strSource);

        if (this._lblFileName == null)
        {
            //MySystem.s_printOutError(this, strMethod, "nil this._lblFileName");
            return false;
        }

        this._lblFileName.setText(strName);


        super.setVisible(true);
        return true;
    }


    // -------
    // PRIVATE

    private JLabel _lblFileName = null;
    private JTextPane _tpeFileSource = null;

    private JPanel _createPanelFilePath()
    {
        JPanel pnl = new JPanel();
        this._lblFileName = new JLabel();
        this._lblFileName.setText(_f_s_strFilePathNo);
        pnl.add(this._lblFileName);
        return pnl;
    }

    private JPanel _createPanelOkButton()
    {
        JPanel pnl = new JPanel();

        this._btnClose = new BtnIcnCloseWindow((ActionListener) this);

        pnl.add(this._btnClose);
        return pnl;
    }


    private void _cancel()
    {
        super._cancel_();

        this._lblFileName.setText(_f_s_strFilePathNo);
        this._tpeFileSource.setText(_f_s_strFileSourceNo);
    }

    private BtnAbs _btnClose = null;
}
